#pragma once

#include <iostream>
#include <string>
#include <cstring>
#include <memory>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <vector>
#include <functional>
#include <thread>
#include "nocopy.h"

using namespace std;

class Inet_data
{
public:
    Inet_data(int sockfd, const sockaddr_in &tmp)
        : _ip(tmp.sin_addr.s_addr), _port(tmp.sin_port), _sockfd(sockfd), _sock(tmp)
    {
    }

    int get_sockfd()
    {
        return _sockfd;
    }
    int get_sockfd() const
    {
        return _sockfd;
    }

    uint16_t get_port()
    {
        return _port;
    }
    uint16_t get_port() const
    {
        return _port;
    }

    in_addr_t get_ip()
    {
        return _ip;
    }
    in_addr_t get_ip() const
    {
        return _ip;
    }

    bool operator==(const Inet_data &tmp)
    {
        return _ip == tmp._ip && _port == tmp._port;
    }

    bool operator==(const Inet_data &tmp) const
    {
        return _ip == tmp._ip && _port == tmp._port;
    }

    void Inet_info() const
    {
        string client_ip = inet_ntoa(_sock.sin_addr);
        uint16_t client_port = ntohs(_port);
        cout << "sock_fd = " << _sockfd << " client_ip = " << client_ip << " client_port = " << to_string(_port) << endl;
    }

private:
    int _sockfd;
    sockaddr_in _sock;
    in_addr_t _ip;
    uint16_t _port;
};